﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using Editeur_map;

namespace lapinou_game2
{
    class HitControl
    {
        // Two cases : collision.Yes = there is a collision
        //             collision.No = none
        public enum Collision
        {
            Yes,
            No
        }

        private BoundingBox[] elementsBoundingBox;

        // To get the current Boundings elements
        public BoundingBox[] getElementsBoundingBox()
        {
            return elementsBoundingBox;
        }

        // To generate automatically the Boundings box array
        public HitControl(Map_State mapToHitTest, int xdecalage, int ydecalage)
        {
            List<BoundingBox> bbList = new List<BoundingBox>();

            foreach (Node node in mapToHitTest.list_node)
            {
                Vector3[] tempPoints = new Vector3[2];
                tempPoints[0] = new Vector3(node.pos.X + node.x_decalage  + xdecalage, node.pos.Y + node.y_decalage + ydecalage, 0);
                tempPoints[1] = new Vector3(node.pos.X + node.x_decalage + 35 + xdecalage, node.pos.Y + node.y_decalage + 35 + ydecalage, 0);
                BoundingBox tempBox = BoundingBox.CreateFromPoints(tempPoints);
                bbList.Add(tempBox);
            }
            elementsBoundingBox = bbList.ToArray();
        }

        // Get a response for the test (update method)
        public Collision getHitTestValue(BoundingSphere nextRabArea)
        {
            for (int i = 0; i < elementsBoundingBox.Length; i++)
            {
                if (elementsBoundingBox[i].Contains(nextRabArea) != ContainmentType.Disjoint)
                    return Collision.Yes;
            }
            return Collision.No;
        }

        public void clearBoundingList()
        {
            elementsBoundingBox.Initialize();            
        }


    }
}
